package logics 
{
	import adobe.utils.CustomActions;
	import constants.Events;
	import constants.States;
	import flash.events.Event;
	import interfaces.logos;
	import vessels.Vessel;
	/**
	 * ...
	 * @author parasitic
	 */
	public class StateMachine extends Logic
	{
		private var state:String;
		
		//right way to code this?
		private var registeredUnit:Vessel;
		
		private function startbuild_handler(e:CustomEvent):void
		{
			setState(States.NOW_BUILDING);
		}
		
		private function setfree_handler(e:CustomEvent):void
		{
			setState(States.FREE);
		}
		
		public function getState():String
		{
			return state;
		}
		
		private function setState(s:String):void
		{
			state = s;
		}
		
		private function cameramoving_handler(e:CustomEvent):void
		{
			setState(States.CAMERA_MOVING);
		}
		
		private function cameramoved_handler(e:CustomEvent):void
		{
			setState(States.FREE);
		}
		
		private function unitselected_handler(e:CustomEvent):void
		{
			//for now...
			setState(States.UNIT_SELECTED);
			registeredUnit = e.args;
		}
		
		override protected function init(e:Event):void
		{
			super.init(e);
			newListener(Events.SET_FREE, setfree_handler);
			newListener(Events.START_BUILD, startbuild_handler);
			newListener(Events.CAMERA_MOVING, cameramoving_handler);
			newListener(Events.CAMERA_MOVED, cameramoved_handler);
			newListener(Events.UNIT_SELECTED, unitselected_handler);
		}
		
		public function StateMachine(s:StateMachine=null) 
		{
			super(s);
		}
		
	}

}